package com.globallogic.oopbasics.competence.io;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import com.globallogic.oopbasics.competence.entity.Specialist;
import com.globallogic.oopbasics.competence.exception.LevelException;

public class SpecialistScanner extends ReadWithScanner {

	private List<Specialist> specialists;

	public List<Specialist> getSpecialists() {
		return specialists;
	}

	public SpecialistScanner(String aFileName) throws FileNotFoundException,
			IllegalArgumentException, LevelException {
		super(aFileName);
	}

	@Override
	protected void init() {
		specialists = new ArrayList<Specialist>();
	}

	/**
	 * Overridable method for processing lines in different ways.
	 */
	@Override
	protected void processLine(String aLine) {
		// use a second Scanner to parse the content of each line
		Scanner scanner = new Scanner(aLine);
		scanner.useDelimiter("~");
		if (scanner.hasNext()) {

			int id = scanner.nextInt();
			String name = scanner.next();
			String surname = scanner.next();

			specialists.add(new Specialist(id, name, surname));

		} else {
			throw new IllegalArgumentException(
					"Empty or invalid line. Unable to process.");
		}
	}
}
